﻿Imports System.Data.SqlClient

Public Class frmQuanLyPhieuNhap
    Dim pn As CPhieuNhap
    Dim mh As CMatHang
    
    Private Sub btnThem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThem.Click
        Dim frmThem As New frmThemPhieuNhapKho
        frmThem.Show()
        frmThem.MdiParent = frmMain
    End Sub

    Private Sub btnXoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoa.Click
        CPhieuNhap.Delete(txtMaPhieuNhap.Text)
        dgvDanhSachPhieuNhap.Rows.RemoveAt(dgvDanhSachPhieuNhap.CurrentRow.Index)
    End Sub

    Private Sub dgvCTPhieuNhap_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgvDanhSachPhieuNhap.SelectionChanged
        Dim index = dgvDanhSachPhieuNhap.CurrentRow.Index
        Dim row = dgvDanhSachPhieuNhap.Rows.Item(index)
        txtMaPhieuNhap.Text = row.Cells(0).Value.ToString()
        dtpNgayNhap.Text = row.Cells(1).Value.ToString()
        txtMaNV.Text = row.Cells(2).Value.ToString()
        dgvThongTinSanPham.DataSource = CKiemTra.LoadDS("select * from CTPHIEUNHAPKHO where MaPhieuNhap = '" + txtMaPhieuNhap.Text + "'")
    End Sub

    Private Sub btnSua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSua.Click
        pn = New CPhieuNhap
        mh = New CMatHang
        pn.MaPhieuNhap = Integer.Parse(txtMaPhieuNhap.Text)
        pn.MaNhanVien = Integer.Parse(txtMaNV.Text)
        pn.NgayNhap = dtpNgayNhap.Text
        Dim index = dgvThongTinSanPham.CurrentRow.Index
        Dim row = dgvThongTinSanPham.Rows.Item(index)
        mh.MaMH = row.Cells(0).Value.ToString()
        mh.Loai = row.Cells(1).Value.ToString()
        mh.DonVi = row.Cells(2).Value.ToString()
        mh.Gia = row.Cells(3).Value.ToString()

        CPhieuNhap.Update(pn, mh)
    End Sub

    Private Sub btnDong_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDong.Click
        Close()
    End Sub

    Private Sub frmQuanLyPhieuNhap_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.WindowState = FormWindowState.Maximized
        txtMaPhieuNhap.Enabled = False
        dgvDanhSachPhieuNhap.DataSource = CPhieuNhap.LoadDS()
    End Sub
End Class